export default {
  //1.添加一个新任务的实际方法
  ADDTODO(state, todoName) {
    // console.log(state, todoName)
    state.todoList.unshift({
      id: Date.now(),
      todoName,
      done: false,
    })
  },

  //2.更改任务状态的方法
  UPDATETODOSTATE(state, id) {
    const todo = state.todoList.find((item) => item.id === id)
    todo.done = !todo.done
  },

  //3.删除一个任务
  DELONETODO(state, id) {
    state.todoList = state.todoList.filter((item) => item.id !== id)
  },

  //4.更改所有任务状态
  CHECKALLTODOS(state, val) {
    state.todoList.forEach((item) => (item.done = val))
  },

  //5.删除所有完成项
  DELALL(state) {
    state.todoList = state.todoList.filter((item) => !item.done)
  },

  //6.更新任务项
  UPDATETODO(state, payload) {
    const item = state.todoList.find((item) => item.id === payload.id)
    item.todoName = payload.todoName
  },
  CHANGESTATE(state, num) {
    state.showState = num
  },
}
